import%20marimo%0A%0A__generated_with%20%3D%20%220.17.6%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22%2C%20auto_download%3D%5B%22html%22%2C%20%22ipynb%22%5D)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20import%20pytz%0A%20%20%20%20import%20datetime%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20india_timezone%20%3D%20pytz.timezone(%22Asia%2FKolkata%22)%0A%20%20%20%20now%20%3D%20datetime.datetime.now(india_timezone)%0A%0A%20%20%20%20curr%20%3D%20now.strftime(%22%25Y-%25m-%25d%2C%20%25I%3A%25M%3A%25S%20%25p%20%25Z%22)%0A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20rf%22%22%22%0A%20%20%20%20%23%20Week%20-%201%0A%0A%20%20%20%20**Submission%20Date%3A**%20%60This%20assignment%20will%20not%20be%20graded%20and%20is%20only%20for%20practice.%60%0A%0A%20%20%20%20**Last%20Updated%3A**%20%60%7Bcurr%7D%60%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20pandas%20as%20pd%0A%20%20%20%20return%20(pd%2C)%0A%0A%0A%40app.cell%0Adef%20_(pd)%3A%0A%20%20%20%20df%20%3D%20pd.read_csv(%22Week-1%2FPractice%20Assignment%2Fdataset.csv%22)%0A%20%20%20%20return%20(df%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Basic%20Dataset%20Inspection%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20assert%20df.shape%20%3D%3D%20(9450%2C%2013)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20df.head()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20df.describe()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20df.info()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%201%0A%0A%20%20%20%20What%20is%20the%20average%20of%20the%20flight%20ticket%20price%3F%20Write%20your%20answer%20correct%20to%20two%20decimal%20places.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20round(df%5B%22Price%22%5D.mean()%2C%202)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%202%0A%0A%20%20%20%20During%20which%20month%20did%20the%20highest%20number%20of%20flights%20occur%3F%20Months%20are%20represented%20by%20numerical%20codes%2C%20with%20January%20corresponding%20to%201%2C%20February%20to%202%2C%20and%20so%20forth.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20df.groupby(%22Month%22)%5B%22Airline%22%5D.count().sort_values(ascending%3DFalse)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20df%5B%22Month%22%5D.mode()%5B0%5D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%203%0A%0A%20%20%20%20Is%20the%20average%20price%20of%20flight%20tickets%20higher%20on%20weekends%20(Saturday%20and%20Sunday)%20or%20on%20weekdays%20(Remaining%205%20days)%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df%2C%20mo)%3A%0A%20%20%20%20weekends%20%3D%20%5B%22Saturday%22%2C%20%22Sunday%22%5D%0A%0A%20%20%20%20_weekend_avg%20%3D%20df%5Bdf%5B%22WeekDay%22%5D.isin(weekends)%5D%5B%22Price%22%5D.mean()%0A%20%20%20%20_weekday_avg%20%3D%20df%5B~df%5B%22WeekDay%22%5D.isin(weekends)%5D%5B%22Price%22%5D.mean()%0A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20f%22%22%22%0A%20%20%20%20**Average%20price%20on%20weekends%3A**%20%7B_weekend_avg%3A.2f%7D%20%20%0A%20%20%20%20**Average%20price%20on%20weekdays%3A**%20%7B_weekday_avg%3A.2f%7D%20%20%0A%0A%20%20%20%20**Conclusion%3A**%20%7B'Weekend'%20if%20_weekend_avg%20%3E%20_weekday_avg%20else%20'Weekday'%7D%20prices%20are%20higher.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%20(weekends%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%204%0A%0A%20%20%20%20Two%20of%20the%20entries%20in%20the%20'Additional_Info'%20column%20are%20'No%20info'%20and%20'No%20Info'.%20Replace%20all%20occurrences%20of%20'No%20Info'%20with%20'No%20info'.%20How%20many%20flights%20fall%20under%20airline%20'IndiGo'%20and%20have%20'No%20info'%20as%20additional%20information%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20df.replace(%22No%20Info%22%2C%20%22No%20info%22%2C%20inplace%3DTrue)%0A%20%20%20%20((df%5B%22Airline%22%5D%20%3D%3D%20%22IndiGo%22)%20%26%20(df%5B%22Additional_Info%22%5D%20%3D%3D%20%22No%20info%22)).sum()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%205%0A%0A%20%20%20%20Convert%20the%20values%20of%20'Duration'%20into%20seconds.%20Enter%20the%20average%20duration%20(in%20seconds)%20of%20a%20flight.%20Enter%20your%20answer%20correct%20to%20two%20decimal%20places.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.function%0Adef%20convert_duration_to_sec(val)%3A%0A%20%20%20%20_val%20%3D%20val.split(%22%20%22)%0A%0A%20%20%20%20h%2C%20m%20%3D%200%2C%200%0A%20%20%20%20match%20len(_val)%3A%0A%20%20%20%20%20%20%20%20case%201%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20_val%20%3D%20_val%5B0%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20%22h%22%20in%20_val%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20h%20%3D%20int(_val%5B%3A-1%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20%22m%22%20in%20_val%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20m%20%3D%20int(_val%5B%3A-1%5D)%0A%20%20%20%20%20%20%20%20case%202%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20h%2C%20m%20%3D%20_val%0A%20%20%20%20%20%20%20%20%20%20%20%20h%20%3D%20int(h%5B%3A-1%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20m%20%3D%20int(m%5B%3A-1%5D)%0A%20%20%20%20%20%20%20%20case%20_%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(f%22Got%20unexpected%20value%3A%20%7Bval%7D%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20return%200%0A%20%20%20%20return%20h%20*%2060%20*%2060%20%2B%20m%20*%2060%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20df%5B%22Duration_in_seconds%22%5D%20%3D%20df%5B%22Duration%22%5D.apply(convert_duration_to_sec)%0A%20%20%20%20assert%20len(df%5B%22Duration%22%5D.unique())%20%3D%3D%20len(df%5B%22Duration_in_seconds%22%5D.unique())%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20round(df%5B%22Duration_in_seconds%22%5D.mean()%2C%202)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Question%206%20-%207%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Apply%20the%20following%20functions%20to%20the%20columns%20Dep_Time%20and%20Arrival_Time%3A%0A%0A%20%20%20%20Transform%20the%20values%20in%20the%20'dep_time'%20and%20'arrival_time'%20columns%20to%20represent%20the%20hour%20component.%20For%20instance%2C%20if%20an%20entry%20is%2010%3A05%20June%2013%20or%2010%3A05%2C%20the%20corresponding%20value%20should%20be%2010.%0A%0A%20%20%20%20Then%20convert%20the%20time%20into%20four%20categories%20as%20follows%3A%0A%0A%20%20%20%20-%205%20%3C%3D%20hour%20%3C%2012%20%3D%20%60Morning%60%0A%20%20%20%20-%2012%20%3C%3D%20hour%20%3C%2017%20%3D%20%60Afternoon%60%0A%20%20%20%20-%2017%20%3C%3D%20hour%20%3C%2020%20%3D%20%60Evening%60%0A%20%20%20%20-%2020%20%3C%3D%20hour%20%3C%205%20%3D%20%60Night%60%0A%0A%20%20%20%20**Note%3A**%20Please%20ensure%20that%20you%20make%20the%20changes%20directly%20within%20the%20dataset%20and%20continue%20to%20use%20that%20modified%20dataset%20for%20subsequent%20questions.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.function%0Adef%20get_time_category(val)%3A%0A%20%20%20%20h%20%3D%20int(val.split(%22%3A%22%2C%201)%5B0%5D)%0A%20%20%20%20if%205%20%3C%3D%20h%20%3C%2012%3A%0A%20%20%20%20%20%20%20%20return%20%22Morning%22%0A%20%20%20%20elif%2012%20%3C%3D%20h%20%3C%2017%3A%0A%20%20%20%20%20%20%20%20return%20%22Afternoon%22%0A%20%20%20%20elif%2017%20%3C%3D%20h%20%3C%2020%3A%0A%20%20%20%20%20%20%20%20return%20%22Evening%22%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20return%20%22Night%22%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20df%5B%22dep_cat%22%5D%20%3D%20df%5B%22Dep_Time%22%5D.apply(get_time_category)%0A%20%20%20%20df%5B%22arrival_cat%22%5D%20%3D%20df%5B%22Arrival_Time%22%5D.apply(get_time_category)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%206%0A%0A%20%20%20%20How%20many%20flights%20started%20in%20the%20Morning%20and%20arrived%20the%20destination%20at%20Evening%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20df%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20((df%5B%22dep_cat%22%5D%20%3D%3D%20%22Morning%22)%20%26%20(df%5B%22arrival_cat%22%5D%20%3D%3D%20%22Evening%22)).sum()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%207%0A%0A%20%20%20%20Encode%20the%20values%20of%20column%20'WeekDay'%20as%20follows%3A%0A%0A%20%20%20%20-%20Weekends%20(Sunday%2C%20Saturday)%20%3D%201%0A%20%20%20%20-%20all%20remaining%20five%20days%20%3D%200%0A%0A%20%20%20%20What%20is%20the%20most%20frequent%20(mode)%20WeekDay%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df%2C%20weekends)%3A%0A%20%20%20%20%23%20df.loc%5Bdf%5B%22WeekDay%22%5D.isin(weekends)%2C%20%22week_encode%22%5D%20%3D%201%0A%20%20%20%20%23%20df.loc%5B~df%5B%22WeekDay%22%5D.isin(weekends)%2C%20%22week_encode%22%5D%20%3D%200%0A%0A%20%20%20%20df%5B%22week_encode%22%5D%20%3D%20df%5B%22WeekDay%22%5D.isin(weekends).astype(int)%0A%0A%20%20%20%20df%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20df%5B%22week_encode%22%5D.mode()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df%2C%20weekends)%3A%0A%20%20%20%20df%5B%22WeekDay%22%5D.isin(weekends).astype(int).mode()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
7dea90aca83655278abf6361b4d845aee9f7085a983fc4624c095ca6924fa59e